package com.arpa.wms.cancel.delivery.context;

import com.arpa.wms.cancel.delivery.AbstractDeliveryCancelHandler;
import com.arpa.wms.domain.entity.Delivery;
import com.arpa.wms.service.IDeliveryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 上下文 用一个map来维护，获取所有有HandlerType的类
 * @author leo
 */
@Service
public class DeliveryCancelHandlerContext {

    @Resource
    private final Map<String, AbstractDeliveryCancelHandler> handlerMap = new ConcurrentHashMap<>();

    public DeliveryCancelHandlerContext(Map<String, AbstractDeliveryCancelHandler> handlerMap) {
        handlerMap.forEach(this.handlerMap::put);
    }

    public void getMethodResult(IDeliveryService deliveryService, String method, Delivery delivery){
        handlerMap.get(method).handle(deliveryService, delivery);
    }

}
